# from 目录1.目录2.目录3.文件名 import  类名，或者函数名

# import random
#
# random.randint()

# from random import randint,choices
# randint()
# choices
#
# from random import *
# randint()
'''
from selenium import  webdriver

driver = webdriver.Chrome()
#元素的定位方式
element = driver.find_element_by_xpath()
element.click()
element.send_keys()
element.clean()

element.text
element.size
element.get_attribute()

driver.current_url
driver.current_window_handle
driver.window_handles
driver.page_source
driver.title

#鼠标事件
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).click()
ActionChains(driver).move_to_element()
ActionChains(driver).context_click()
ActionChains(driver).drag_and_drop()


# 键盘事件
from selenium.webdriver.common.keys import Keys
element.send_keys(Keys.ENTER)
element.send_keys(Keys.CONTROL,"a")


#上传文件
element.send_keys("文件的位置")

import autoit
autoit.control_set_text()
autoit.control_click()

#截图
driver.save_screenshot("图片保存的位置")

#如果元素定位找不到，有可能是什么原因
# 表达式写错了
# 需要切换iframe，或者window ，解决方式切换， driver.switch_to.window(),driver.switch_to.frame()
# 页面加载太慢，要找的元素没有加载出来， 解决方式，加等待
# 通过定位找到的元素有多个
 '''


from selenium import  webdriver
import time
from selenium.webdriver.support.wait import WebDriverWait
from  selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
# driver.implicitly_wait(5)
# driver.get("https://www.baidu.com/")
# driver.find_element(by=By.ID,value='kw').send_keys("123")
# driver.find_element(by=By.ID,value='su').click()

# 通过执行javaScript脚本语言移动混动条
# driver.execute_script("window.scrollTo(500,100)")
# time.sleep(3)
# driver.execute_script("window.scrollTo(500,100)")
# time.sleep(3)
# driver.execute_script("window.scrollBy(500,100)")
# time.sleep(3)
# driver.execute_script("window.scrollBy(500,100)")
# time.sleep(3)
# driver.execute_script("window.scrollBy(500,100)")

# 等待分三种方式，强制等待，隐式等待，显示等待

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

driver.get("http://192.168.0.138:9000/ECShop_V2.7.2_UTF8_Release0604/upload66/user.php")

# wait = WebDriverWait(driver,"最长等待时间")
# wait.until("方法",message="如果元素没有定位到，报错会打印的信息") #返回值是元素
# #方法
# EC.presence_of_element_located((By.NAME,"定位的值"))
# EC.visibility_of(driver.find_element_by_name())


# 如果是located传参数的时候，传的是元素定位方式
ele1 = WebDriverWait(driver,5).until(EC.presence_of_element_located((By.NAME,"username")),message="输入用户名定位失败")
ele1.send_keys("123")
# 如果是element传参数的时候，传的是元素
ele2  = WebDriverWait(driver,5,0.1).until(EC.visibility_of(driver.find_element_by_name("password")),message="输入密码定位失败")
ele2.send_keys("123456")
# ele3 = WebDriverWait(driver,5).until(EC.presence_of_element_located((By.NAME,"submit")),message="元素等位失败后显示的消息")
# ele3.click()
# WebDriverWait(driver,5).until(EC.visibility_of(driver.find_element_by_name("submit")),message='').click()
WebDriverWait(driver,5).until(lambda x:x.find_element_by_name("submit"),message='').click()


time.sleep(2)
driver.quit()


